using System.Collections;
using UnityEngine;

public class Battle_PlayerSoul : MonoBehaviour
{
	public enum SoulType
	{
		Red,
		Blue,
		Yellow
	}

	public enum SoulState
	{
		Disabled,
		Active,
		Cutscene
	}

	[Header("- References -")]
	public Rigidbody2D SoulRigidbody;

	public Animator SoulAnimator;

	[SerializeField]
	private AudioSource _soulSource;

	[Space(5f)]
	[Header("- Settings -")]
	public SoulType CurrentSoulType;

	public SoulState CurrentSoulState;

	[SerializeField]
	private float DefaultMoveSpeed;

	[SerializeField]
	private float DefaultSlowMoveSpeed;

	private float CurrentSoulMoveSpeed;

	public bool DamageCooldown;

	private static Battle_PlayerSoul instance;

	private Vector2 _StoredMoveDIR;

	private bool HoldingSlowKey;

	public static Battle_PlayerSoul Instance => instance;

	private void Awake()
	{
		if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		instance = this;
		((Component)this).gameObject.SetActive(false);
	}

	private void OnEnable()
	{
		DamageCooldown = false;
		instance.SoulAnimator.Play("Idle", 0, 0f);
	}

	private void Update()
	{
		ProcessInputs();
		if (CurrentSoulState == SoulState.Active)
		{
			MoveSoul();
		}
	}

	private void ProcessInputs()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		float horizontalInput = PlayerInput.GetHorizontalInput();
		float verticalInput = PlayerInput.GetVerticalInput();
		_StoredMoveDIR = new Vector2(horizontalInput, verticalInput);
		HoldingSlowKey = Input.GetKey(PlayerInput.Instance.Key_Sprint);
		if (HoldingSlowKey)
		{
			CurrentSoulMoveSpeed = DefaultSlowMoveSpeed;
		}
		else
		{
			CurrentSoulMoveSpeed = DefaultMoveSpeed;
		}
	}

	private void MoveSoul()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		if (CurrentSoulState == SoulState.Active)
		{
			SoulRigidbody.velocity = new Vector2(((Vector2)(ref _StoredMoveDIR)).normalized.x * CurrentSoulMoveSpeed * Time.fixedDeltaTime, ((Vector2)(ref _StoredMoveDIR)).normalized.y * CurrentSoulMoveSpeed * Time.fixedDeltaTime);
		}
	}

	public static void OnSoulHit(Bullet_Generic bullet)
	{
	}

	public static void TakeDamage(Bullet_Generic bullet = null, float amount = 0f)
	{
		if ((Object)(object)Instance != (Object)null && !instance.DamageCooldown)
		{
			OnSoulHit(bullet);
			((MonoBehaviour)instance).StartCoroutine("DamageCooldownFrames");
			instance.SoulAnimator.Play("Hurt", 0, 0f);
			instance._soulSource.PlayOneShot(BattleSystem.Instance.SFX_soul_damage);
		}
	}

	private IEnumerator DamageCooldownFrames()
	{
		DamageCooldown = true;
		yield return (object)new WaitForSeconds(1.5f);
		DamageCooldown = false;
	}
}
